package org.csu.mypetstore.web.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Order;

public class ShippingAdressServlet extends HttpServlet {
    private static final String CONFIRM_ORDER_FORM = "/WEB-INF/jsp/order/ConfirmOrder.jsp";
    private Order order;
    private String shipToFirstName;
    private String shipToLastName;
    private String shipAddress1;
    private String shipAddress2;
    private String shipCity;
    private String shipState;
    private String shipZip;
    private String shipCountry;

    public ShippingAdressServlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.shipToFirstName = request.getParameter("shipToFirstName");
        this.shipToLastName = request.getParameter("shipToLastName");
        this.shipAddress1 = request.getParameter("shipAddress1");
        this.shipAddress2 = request.getParameter("shipAddress2");
        this.shipCity = request.getParameter("shipCity");
        this.shipState = request.getParameter("shipState");
        this.shipZip = request.getParameter("shipZip");
        this.shipCountry = request.getParameter("shipCountry");
        HttpSession session = request.getSession();
        this.order = (Order)session.getAttribute("order");
        this.order.setShipToFirstName(this.shipToFirstName);
        this.order.setShipToLastName(this.shipToLastName);
        this.order.setShipAddress1(this.shipAddress1);
        this.order.setShipAddress2(this.shipAddress2);
        this.order.setShipCity(this.shipCity);
        this.order.setShipState(this.shipState);
        this.order.setShipZip(this.shipZip);
        this.order.setCourier(this.shipCountry);
        session.setAttribute("order", this.order);
        Account account = (Account)session.getAttribute("account");
        request.getRequestDispatcher("/WEB-INF/jsp/order/ConfirmOrder.jsp").forward(request, response);
    }
}
